from django.db import models

# Create your models here.
class WeldTask(models.Model):
    class Meta:
        db_table = "weld"

    project_number = models.CharField(
        verbose_name="项目号",
        max_length=20,
    )
    tube_number = models.CharField(
        verbose_name="管道号",
        max_length=20,
        null=True,
    )
    tube_length = models.FloatField(
        verbose_name="管道长度",
        null=True,
    )
    material = models.CharField(
        verbose_name="材料",
        max_length=20,
        null=True,
    )
    weldtype = models.CharField(
        verbose_name="焊接接头类型",
        max_length=20,
        null=True,
        )
    part_name = models.CharField(
        verbose_name="名称",
        max_length=100,
    )
    inspector = models.ForeignKey(
        verbose_name="检查员",
        to="user.User",
        on_delete=models.CASCADE,
        related_name="inspector2",
        null=True,
    )
    
    inspect_date = models.DateField(verbose_name="检查日期", null=True)
    reviewer = models.ForeignKey(
        verbose_name="审核",
        to="user.User",
        on_delete=models.CASCADE,
        related_name="reviewer2",
        null=True,
    )
    review_date = models.DateField(verbose_name="审核日期", null=True)
    
    
    
class WeldVideo(models.Model):
    class Meta:
        db_table="video"
    standard = models.CharField(
        verbose_name="标准",
        max_length=20,
        blank=True,
    )
    video_number =models.CharField(
        verbose_name="视频代号",
        max_length=20,
    )
    weld_length = models.FloatField(
        verbose_name="焊缝长度",
        null=True,
    )
    velocity = models.FloatField(
        default=1.0,
        verbose_name="速度",
    )
    evaluation = models.TextField(
        verbose_name="评定结果",
        blank=True,
    )
    note = models.TextField(
        verbose_name="备注",
        blank=True,
    )
    project = models.ForeignKey(
        verbose_name="项目", to="WeldTask", on_delete=models.CASCADE
    )
    video = models.FileField(
        verbose_name="视频",upload_to='data/videos',null=True,blank=True
    )
    ratio = models.FloatField(
        verbose_name="比例尺",default=1.0)
    
class WeldDefects(models.Model):
    class Meta:
        db_table="weld_defect"
    
    video=models.ForeignKey(
        verbose_name="视频",
        to="WeldVideo",
        on_delete=models.CASCADE
    )
    kind=models.CharField(
    verbose_name="缺陷类型",
    max_length=20
    )
    x=models.FloatField(
    verbose_name="横轴位置",
    )
    y=models.FloatField(
    verbose_name="纵轴位置",
    )
    w=models.FloatField(
    verbose_name="宽度",
    )
    h=models.FloatField(
    verbose_name="高度",
    )
    frame_number=models.IntegerField(
    verbose_name="帧号",
    )
    defect = models.FileField(
        verbose_name="缺陷图片",upload_to='data/defects',null=True,blank=True
    )
    note = models.TextField(
        verbose_name="备注",
        blank=True,
    )
